#include "drawrectroaditem.h"


DrawRectRoadItem::DrawRectRoadItem(QObject *parent): QObject(parent)
{
    setFlag(QGraphicsPathItem::ItemIsSelectable);
    setAcceptHoverEvents(true);
//    setAcceptTouchEvents(true);
    m_bStart = true;
}

void DrawRectRoadItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setBrush(QColor(255, 255, 0, 100));
    painter->setPen(QPen(Qt::red, 0.1));


    QRectF qRectF(mapFromScene(m_qPointBegin), mapFromScene(m_qPointEnd));

    this->setRect(qRectF);
//    painter->rotate(5); //道路转角度，后期会用到
    painter->drawRect(qRectF);
}

QRectF DrawRectRoadItem::getLink() const
{
    QRectF qRectF(mapFromScene(m_qPointBegin), mapFromScene(m_qPointEnd));

    return qRectF; //接口，作为画连接的连接点
}

void DrawRectRoadItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    qDebug() << "Mouse Press: " << event->pos();

    QGraphicsItem::mousePressEvent(event);

    emit sendLink(getLink());
}

void DrawRectRoadItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    qDebug() << "Mouse Release: " << event->pos();

    QGraphicsItem::mouseReleaseEvent(event);
}

void DrawRectRoadItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    qDebug() << "Mouse Move: " << event->pos();

    QGraphicsItem::mouseMoveEvent(event);
}

void DrawRectRoadItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
    qDebug() << "hoverMouse Move: " << event->pos();

    QGraphicsItem::hoverMoveEvent(event);
}
